import puppeteer from 'puppeteer';
import axios from 'axios';
import xlsx from 'node-xlsx';
import fs from 'fs';
import setPageContent from 'puppeteer-core';
import GoLogin from '../../src/gologin.js';
import connect from 'puppeteer';

let isRandomMove = true;
let path = 'c://fuel/fuel_address.xlsx';
(async () => {
  // await refreshAccount('!383157zhangHAO',0)
  // startGame('');
  let token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2MzgyMjYxYmJhNjczZWQ2YjU0NTU5NzYiLCJ0eXBlIjoiZGV2Iiwiand0aWQiOiI2NDU0NzlhYzdhZWEzMmVmOWY3Mjk3ZGUifQ.f1Kj2S6iqgKGA5Oep_mfMWiPktEvOP5ZYWnUlF7f3Og';

  const option = process.argv[2].toUpperCase();
  const num = parseInt(process.argv[3]);
  const sheets = xlsx.parse('profiles.xlsx');
  const sheetElement = sheets[1].data[num];
  // const profileId = sheetElement[12];
  const profileId = sheetElement[1];

  // await stepOne(token, profileId);
  function newGL(profileId) {
    let GL = new GoLogin({
      token: token,
      profile_id: profileId,
      extra_params: ['--start-maximized'],
      uploadCookiesToServer: true,
      tmpdir: 'C:\\Users\\Administrator\\AppData\\Local\\Temp\\',
    });
    return GL;
  }



  let GL = newGL(profileId);
  const { status, wsUrl } = await GL.start();
  console.log(wsUrl);

  let id = process.argv[4];

  let data1 = '\n' + id + '|' + wsUrl;

  fs.appendFile('file.txt', data1, function (err) {
    if (!err) {
      console.log('wrote data to file.txt');
    } else {
      throw err;
    }
  });
  GL.commitProfile();
})();


